package com.example.core.controller;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.util.*;

/**
 * @program: service
 * @description: 人群画像
 * @author: admin
 * @create: 2021-05-25 13:46
 **/

public class UserProfileController {
//    public static void main(String[] args) throws IOException {
//
//        try (XSSFWorkbook wb = new XSSFWorkbook()) {
//            XSSFSheet sheet = wb.createSheet("sheet1");
//            final int NUM_OF_ROWS = 2;
//            final int NUM_OF_COLUMNS = 2;
//
//            Row row;
//            Cell cell;
//
//            row = sheet.createRow(0);
//            cell = row.createCell(0);
//            cell.setCellValue("男");
//            cell = row.createCell(1);
//            cell.setCellValue("女");
//
//            row = sheet.createRow(1);
//            cell = row.createCell(0);
//            cell.setCellValue(10);
//            cell = row.createCell(1);
//            cell.setCellValue(4);
//
//            XSSFDrawing drawing = sheet.createDrawingPatriarch();
//            XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 4, 10, 25);
//            XSSFChart chart = drawing.createChart(anchor);
//            chart.setTitleText("测试标题");
//            chart.setTitleOverlay(false);
//            XDDFChartLegend legend = chart.getOrAddLegend();
//            legend.setPosition(LegendPosition.TOP_RIGHT);
//
//            XDDFDataSource<String> cat = XDDFDataSourcesFactory.fromStringCellRange(
//                    sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)
//            );
//            XDDFNumericalDataSource<Double> val = XDDFDataSourcesFactory.fromNumericCellRange(
//                    sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1)
//            );
//
//            XDDFChartData data = new XDDFPieChartData(chart.getCTChart().getPlotArea().addNewPieChart());
//            data.setVaryColors(true);
//            data.addSeries(cat, val);
//            chart.plot(data);
//
//            //写入
//            try (FileOutputStream fileOut = new FileOutputStream("testChart.xlsx")) {
//                wb.write(fileOut);
//            }
//        }
//    }

    public static void main(String[] args) {


        List<String> sexList = Arrays.asList("男", "男", "男", "男", "男", "女");
        List<String> ageList = Arrays.asList("18", "25", "28", "28", "28", "31", "31", "31", "31", "31", "35", "38", "38", "38", "38", "42", "42", "48", "48", "53", "58", "60");
        List<String> educationList = Arrays.asList("小学及以下", "初中", "高中", "高中", "高中", "专科", "专科", "专科", "专科", "专科", "本科", "本科", "本科", "本科", "本科", "本科", "研究生及以上", "研究生及以上");
        List<String> maritalStatusList = Arrays.asList("已婚", "已婚", "已婚", "未婚", "未婚");
        List<String> industryList = Arrays.asList("政府机关", "政府机关", "制造业", "制造业", "制造业", "制造业"
                , "银行", "医疗", "医疗", "美容", "媒体", "旅游", "建筑", "建筑", "建筑", "教育", "金融", "金融", "房地产", "IT");
        Map<String, List<String>> industryMap = new HashMap<>();
        industryMap.put("政府机关", Arrays.asList("文字综合", "纪检监察", "财务审计"));
        industryMap.put("制造业", Arrays.asList("工艺工程师", "销售工程师", "设备工程师", "机械工程师"));
        industryMap.put("银行", Arrays.asList("柜台主管", "柜员", "客户经理"));
        industryMap.put("医疗", Arrays.asList("护士", "医生"));
        industryMap.put("美容", Arrays.asList("美容师", "理发师", "顾问", "销售"));
        industryMap.put("媒体", Arrays.asList("记者", "导播", "文字工作"));
        industryMap.put("旅游", Arrays.asList("导游", "销售", "顾问", "运营"));
        industryMap.put("金融", Arrays.asList("基金经理", "客户经理", "顾问", "运营"));
        industryMap.put("教育", Arrays.asList("教师", "运营"));
        industryMap.put("建筑", Arrays.asList("工程监理", "施工员","工程师"));
        industryMap.put("房地产", Arrays.asList("销售", "运营","客户经理"));
        industryMap.put("IT", Arrays.asList("软件开发", "软件测试","运维"));


        List<String> incomeList = Arrays.asList("100000", "200000", "300000", "100000", "100000", "100000", "150000", "150000", "250000", "500000");
        List<String> hobbyList = Arrays.asList("打篮球", "游泳", "看电影", "看电影", "看电影", "游戏", "聚会", "聚会", "聚会", "健身", "健身", "健身", "健身", "徒步", "徒步", "钓鱼");
        List<String> vehList = Arrays.asList("B70", "T55", "T55", "T55", "T99", "T99", "T33", "T33", "T77", "T77");
        List<String> vehStatusList = Arrays.asList("首购", "首购", "首购", "首购", "换购", "增购");
        List<String> colorList = Arrays.asList("白色", "白色", "白色", "黑色", "红色", "蓝色", "蓝色", "绿色", "黑色", "黑色", "黑色", "黑色");
        List<String> vehModelList = Arrays.asList("乐享型", "乐享型", "悦享型", "悦享型", "悦享型", "智享型", "尊享型", "驭享型");
        List<String> buyingFactorList = Arrays.asList("大众媒体", "大众媒体", "大众媒体", "广告", "广告", "广告", "广告", "广告", "国产"
                , "国产", "国产", "经济条件", "经济条件", "朋友推荐", "朋友推荐", "朋友推荐", "品牌", "品牌", "品牌", "品牌", "品牌", "省油", "省油", "消费者评价"
                , "消费者评价", "消费者评价", "性价比", "性价比", "性能");
        List<String> mediaList = Arrays.asList("报纸", "杂志", "广播", "广播", "电视", "电视", "电视", "电视", "新媒体", "新媒体", "新媒体", "新媒体", "新媒体", "新媒体");

        XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
        XSSFSheet xssfSheet = xssfWorkbook.createSheet("sheet1");
        XSSFRow titleRow = xssfSheet.createRow(0);
        titleRow.createCell(0).setCellValue("id");
        titleRow.createCell(1).setCellValue("region");
        titleRow.createCell(2).setCellValue("province");
        titleRow.createCell(3).setCellValue("city");
        titleRow.createCell(4).setCellValue("sex");
        titleRow.createCell(5).setCellValue("age");
        titleRow.createCell(6).setCellValue("education");
        titleRow.createCell(7).setCellValue("marital_status");
        titleRow.createCell(8).setCellValue("industry");
        titleRow.createCell(9).setCellValue("profession");
        titleRow.createCell(10).setCellValue("income");
        titleRow.createCell(11).setCellValue("hobby");
        titleRow.createCell(12).setCellValue("vehicle_type");
        titleRow.createCell(13).setCellValue("vehicle_status");
        titleRow.createCell(14).setCellValue("vehicle_color");
        titleRow.createCell(15).setCellValue("vehicle_interior");
        titleRow.createCell(16).setCellValue("vehicle_model");
        titleRow.createCell(17).setCellValue("buying_factor");
        titleRow.createCell(18).setCellValue("media");
        titleRow.createCell(19).setCellValue("statistical_time");

        for (int i = 0; i < 10000; i++) {
            XSSFRow xssfRow = xssfSheet.createRow(i + 1);
            xssfRow.createCell(0).setCellValue(i + 1);
            xssfRow.createCell(1).setCellValue("");
            xssfRow.createCell(2).setCellValue("");
            xssfRow.createCell(3).setCellValue("");

            xssfRow.createCell(4).setCellValue(sexList.get(new Random().nextInt(sexList.size())));
            xssfRow.createCell(5).setCellValue(ageList.get(new Random().nextInt(ageList.size())));
            xssfRow.createCell(6).setCellValue(educationList.get(new Random().nextInt(educationList.size())));
            xssfRow.createCell(7).setCellValue(maritalStatusList.get(new Random().nextInt(maritalStatusList.size())));

            String temp = industryList.get(new Random().nextInt(industryList.size()));
            xssfRow.createCell(8).setCellValue(temp);
            List<String> tempList = industryMap.get(temp);
            xssfRow.createCell(9).setCellValue(tempList.get(new Random().nextInt(tempList.size())));

            xssfRow.createCell(10).setCellValue(incomeList.get(new Random().nextInt(incomeList.size())));
            xssfRow.createCell(11).setCellValue(hobbyList.get(new Random().nextInt(hobbyList.size())));
            xssfRow.createCell(12).setCellValue(vehList.get(new Random().nextInt(vehList.size())));
            xssfRow.createCell(13).setCellValue(vehStatusList.get(new Random().nextInt(vehStatusList.size())));
            xssfRow.createCell(14).setCellValue(colorList.get(new Random().nextInt(colorList.size())));
            xssfRow.createCell(15).setCellValue(colorList.get(new Random().nextInt(colorList.size())) + "超纤");
            xssfRow.createCell(16).setCellValue(vehModelList.get(new Random().nextInt(vehModelList.size())));
            xssfRow.createCell(17).setCellValue(buyingFactorList.get(new Random().nextInt(buyingFactorList.size())));
            xssfRow.createCell(18).setCellValue(mediaList.get(new Random().nextInt(mediaList.size())));
            xssfRow.createCell(19).setCellValue("2021-08-18");
        }

        try (FileOutputStream fileOut = new FileOutputStream("data.xlsx")) {
            xssfWorkbook.write(fileOut);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
